package com.u2ds.console.web.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.cybermkd.mongo.kit.MongoQuery;
import com.u2ds.console.web.service.CourtService;
import com.u2ds.console.web.util.TypeUtil;
import com.u2ds.core.entity.BaseEntity;
import com.u2ds.dss.entity.court.CourtInfo;
import com.u2ds.dss.entity.court.CourtOrder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * Created by Ethan.Yuan on 2017/8/23.
 */
@Service("courtService")
public class CourtServiceImpl implements CourtService {

    /**
     * 根据卡的类型创建商品视图
     * @param cardType
     * @return
     */
    @Override
    public List<JSONObject> createProductView(String cardType, Date date) {
        MongoQuery mongoQuery = new MongoQuery();
        //0. 获取所有的场地
        List<JSONObject> courtInfoList = mongoQuery.use(CourtInfo.class.getSimpleName()).eq(CourtInfo.status, TypeUtil.STATUS_VALID).find();
        List<String> courtIdList = new ArrayList<String>(courtInfoList.size());
        courtInfoList.forEach(item -> {
            courtIdList.add(item.getString(BaseEntity.id));
        });
        //1. 获取所有的订单
        List<JSONObject> orderList = mongoQuery.use(CourtOrder.class.getSimpleName()).in(CourtOrder.status, Arrays.asList(TypeUtil.ORDER_TYPE_CREATED, TypeUtil.ORDER_TYPE_PAID))
                                               .in(CourtOrder.courtId, courtIdList).find();

        return null;
    }
}
